Skip to content

Conversation

@ZUOXIANGE
Copy link

@ZUOXIANGE ZUOXIANGE commented Aug 15, 2025

Summary by CodeRabbit

  • Bug Fixes

    • URI collection properties now correctly resolve as resource types without explicit value-type attributes.
  • Tests

    • Added comprehensive tests for resource-shape creation covering URI collections, getter/setter patterns, and type resolution.
  • Chores

    • Added a new test project and included it in the solution to scaffold unit testing and code-coverage.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 15, 2025

Walkthrough

Adds type-to-value-type mappings for URI collection types (ICollection, IEnumerable, ISet) to ResourceShapeFactory, scaffolds a new unit test project with comprehensive test coverage for ResourceShapeFactory.CreateResourceShape including six test resource classes, and registers the test project in the solution file.

Changes

Cohort / File(s) Summary
Core Type Mappings
OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs
Adds three entries to the TYPE_TO_VALUE_TYPE static dictionary mapping ICollection<Uri>, IEnumerable<Uri>, and ISet<Uri> to ValueType.Resource, enabling URI collections to resolve as resource types.
Test Project Setup
OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/OSLC4Net.Core.Tests.csproj
Creates new .NET 10.0 test project and references core projects; adds test dependencies (xunit.v3, NSubstitute, coverlet.collector, CommunityToolkit.Diagnostics, Microsoft.Extensions.Logging.Abstractions, Meziantou.Extensions.Logging.Xunit.v3, Microsoft.Extensions.Hosting, Microsoft.NET.Test.Sdk).
Test Suite & Resources
OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs
Implements ResourceShapeFactoryTests with multiple test methods validating CreateResourceShape behavior across various collection/property patterns and adds six test resource classes (getter/setter patterns, arrays, lists, ICollection, HashSet, ISet scenarios).
Solution Configuration
OSLC4Net_SDK/OSLC4Net.Core.slnx
Registers new test project OSLC4Net.Core.Tests/OSLC4Net.Core.Tests.csproj in the solution under the Tests folder.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Test as Test Runner
    participant RSF as ResourceShapeFactory
    participant TypeMap as TYPE_TO_VALUE_TYPE

    Note over Test,RSF: Test invokes CreateResourceShape for types with URI collections
    Test->>RSF: CreateResourceShape(TypeWithUriCollection)
    RSF->>TypeMap: Lookup collection component type (ICollection/ IEnumerable/ ISet of Uri)
    TypeMap-->>RSF: ValueType.Resource
    RSF-->>Test: ResourceShape with property mapped as Resource (occurs as appropriate)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review ResourceShapeFactory type mapping additions for consistency with existing type-resolution logic.
  • Verify test assertions and constants (BaseUri, ResourceShapesPath, ResourceShapePath) match expected RDF/IRI values.
  • Inspect test resource classes to ensure they exercise getter/setter vs direct property patterns correctly.
  • Check the project file target framework and dependency scopes for CI compatibility.

Poem

🐇 I hopped through maps of types and clues,
I nudged three URIs into resource shoes,
Tests now bustle, getters dance in line,
Arrays and lists sing, the shapes align,
A joyful rabbit stamps the passing tests — hooray! 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: CreateResourceShape TYPE_TO_VALUE_TYPE KeyNotFound' clearly identifies the main change: fixing a KeyNotFoundException in the CreateResourceShape method by adding TYPE_TO_VALUE_TYPE mappings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8975a4 and 657a519.

📒 Files selected for processing (1)
  • OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/OSLC4Net.Core.Tests.csproj (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/OSLC4Net.Core.Tests.csproj

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (3)

8-9: Use English for all code comments.

The XML documentation comment is in Chinese. According to Microsoft Framework design guidelines, code comments should be in English for consistency and maintainability.

/// <summary>
-/// 测试ResourceShapeFactory.CreateResourceShape方法
+/// Tests for the ResourceShapeFactory.CreateResourceShape method
/// </summary>

91-91: Use English for all code comments.

The inline comment is in Chinese. Keep all comments in English for consistency.

-        // ResourceShapeFactory只处理以Get或Is开头的方法,Requirement类只有从AbstractResourceRecord继承的GetTypes()方法
+        // ResourceShapeFactory only processes methods starting with Get or Is, Requirement class only has GetTypes() method inherited from AbstractResourceRecord

10-15: Consider using more descriptive constant names.

The constants could be more descriptive to better reflect their purpose in the OSLC context.

-    private const string BaseUri = "http://example.com";
-    private const string ResourceShapesPath = "resourceShapes";
-    private const string ResourceShapePath = "requirement";
+    private const string TestBaseUri = "http://example.com";
+    private const string OslcResourceShapesPath = "resourceShapes";
+    private const string RequirementResourceShapePath = "requirement";
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2c6244f and e9042f1.

📒 Files selected for processing (4)
  • OSLC4Net_SDK/OSLC4Net.Core.sln (3 hunks)
  • OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs (1 hunks)
  • OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/OSLC4Net.Core.Tests.csproj (1 hunks)
  • OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

⚙️ CodeRabbit Configuration File

**/*.cs: Review the C# code against the Microsoft Framework design guidelines as well as 10 guidelines
from "Building Maintainable Software" by Joost Visser. Point out deviations and improvements.

Files:

  • OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs
  • OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs
🧬 Code Graph Analysis (2)
OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs (1)
OSLC4Net_SDK/OSLC4Net.Core/Model/ValueType.cs (2)
  • ValueType (69-82)
  • ValueType (84-87)
OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (3)
OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs (3)
  • ResourceShapeFactory (26-511)
  • ResourceShapeFactory (38-57)
  • ResourceShapeFactory (59-61)
OSLC4Net_SDK/OSLC4Net.Domains.RequirementsManagement/Constants.cs (1)
  • RM (27-77)
OSLC4Net_SDK/OSLC4Net.Core/Model/TypeFactory.cs (1)
  • GetName (41-47)
🔇 Additional comments (11)
OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs (1)

56-56: LGTM! The mapping addition is correct and addresses the KeyNotFound issue.

The addition of TYPE_TO_VALUE_TYPE[typeof(ICollection<Uri>)] = ValueType.Resource; properly maps URI collections to resource value types. This aligns with the existing pattern where Uri is mapped to ValueType.Resource on line 55, and extends that mapping to collections of URIs, which is semantically correct for OSLC resource relationships.

OSLC4Net_SDK/OSLC4Net.Core.sln (3)

45-46: LGTM! New test project properly added to the solution.

The new test project is correctly defined with the appropriate GUID and path structure following the established patterns in the solution.


217-228: LGTM! Complete configuration coverage for the new test project.

All solution configurations (Debug/Release across Any CPU, Mixed Platforms, and x86) are properly configured for the new test project, ensuring it builds correctly in all scenarios.


241-241: LGTM! Test project properly organized under Tests folder.

The NestedProjects section correctly places the new test project under the Tests solution folder, maintaining the solution's organizational structure.

OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/OSLC4Net.Core.Tests.csproj (1)

1-30: LGTM! Well-structured test project configuration.

The project file follows .NET 8.0 best practices with:

  • Proper targeting (net8.0)
  • Appropriate project references to both core library and domain-specific components
  • Comprehensive test package dependencies including xUnit v3, NSubstitute for mocking, and code coverage tools
  • Correct asset configurations for analyzers and build-time dependencies

The package selection demonstrates good testing practices with modern tooling.

OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (6)

16-33: LGTM! Well-structured basic validation test.

The test follows the AAA pattern correctly and validates the fundamental functionality of resource shape creation including proper URI construction.


35-51: LGTM! Title validation test is well-implemented.

The test properly verifies that the resource shape has the expected title as configured in the Requirement type's attributes.


53-71: LGTM! Describes validation test correctly checks domain URI.

The test properly validates that the resource shape describes the correct OSLC domain URI for requirements management, using proper string comparison.


73-94: LGTM! Properties validation test appropriately checks expected properties.

The test correctly validates that properties are generated and specifically checks for the "type" property, which is expected from the inheritance hierarchy.


96-118: LGTM! Detailed type property validation is thorough.

The test provides comprehensive validation of the type property including its name, value type, occurrence, and RDF property definition URI, ensuring proper OSLC compliance.


120-138: LGTM! Getter method filtering validation is appropriate.

The test correctly verifies that only getter methods are processed by the ResourceShapeFactory, confirming the expected behavior of filtering out setter methods and other non-getter methods.

@codecov
Copy link

codecov bot commented Aug 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.76%. Comparing base (3d5a229) to head (657a519).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #389      +/-   ##
==========================================
+ Coverage   49.56%   50.76%   +1.20%     
==========================================
  Files         166      166              
  Lines       15390    15393       +3     
  Branches     1024     1024              
==========================================
+ Hits         7628     7815     +187     
+ Misses       7479     7271     -208     
- Partials      283      307      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@berezovskyi
Copy link
Member

berezovskyi commented Aug 15, 2025

Thanks for the PR, @ZUOXIANGE!

I am away from a computer for a week or so - reviewing from phone.

First, a question: do the tests fail if we comment out your new mapping entry? I did not see Uri collections tested explicitly.

Second, I think it would be better to map all collection types in a consistent way - did you check how other backing types than ICollection are handled? E.g. List<Uri>, HashSet<Uri>, Uri[]? There a bit of Java-style legacy code (most of the code was written by IBMers between 2009-2013 and I started actively maintaining the lib and to bring into .NET 5+ since late 2023) that only works well with those concrete types and not with the high-level interfaces (I only started it recently in #322). See ExtractTypeInformation() in the DotNetRdfHelper class that I introduced.

Third, I started adding support in #322 for props like ImplementedBy instead of GetImplementedBy and SetImplementedBy. I think I missed to update resource shape handling for that. Would be nice to handle that too but we can file a separate issue for that if it is too much work in this PR.

Finally, we want to be careful with mapping ICollection to Uri* because there are other ways in RDF for representing collections other than repeating a prop multiple times (see https://ontola.io/blog/ordered-data-in-rdf) but we don't need to worry about this now unless you are modifying code that handles that conversion.

P.S. Please update XMLDOC comments to be in English only - see good suggestions from Coderabbit for that under Nitpick Comments.

@ZUOXIANGE
Copy link
Author

While creating the ResourceShape for Requirements, I encountered a KeyNotFoundException that required immediate attention to keep our development pipeline unblocked. I've implemented a temporary fix by adding the necessary code to resolve this specific scenario. I'd greatly appreciate your expertise in reviewing these changes to ensure they align with the project's architectural standards.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (6)
OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (6)

1-5: Organize imports according to C# conventions.

The using directives should be organized with System namespaces first, followed by third-party libraries, then project namespaces. Additionally, there's a missing using System.Linq; import that's required for LINQ operations used throughout the file.

+using System;
+using System.Linq;
 using OSLC4Net.Core.Model;
 using OSLC4Net.Core.Attribute;
 using OSLC4Net.Domains.RequirementsManagement;
 using Xunit;

14-31: Simplify test to focus on single responsibility.

This test validates multiple aspects of the resource shape (non-null checks and URI construction). Consider splitting into focused tests or removing redundant assertions since the URI construction is already validated separately.

 [Fact]
-public void CreateResourceShape_WithRequirementType_ShouldReturnValidResourceShape()
+public void CreateResourceShape_WithRequirementType_ShouldReturnNonNullResourceShape()
 {
     // Arrange
     var resourceType = typeof(Requirement);

     // Act
     var resourceShape = ResourceShapeFactory.CreateResourceShape(
         BaseUri,
         ResourceShapesPath,
         ResourceShapePath,
         resourceType);

     // Assert
     Assert.NotNull(resourceShape);
-    Assert.NotNull(resourceShape.GetAbout());
-    Assert.Equal($"{BaseUri}/{ResourceShapesPath}/{ResourceShapePath}", resourceShape.GetAbout().ToString());
 }

133-135: Test assertion may be too brittle.

Using Assert.Single(properties) assumes exactly one property will always be present. This could break if the Requirement class gains additional OSLC properties. Consider using a more specific assertion.

-Assert.Single(properties);
-Assert.Equal("type", properties[0].GetName());
+var typeProperties = properties.Where(p => p.GetName() == "type").ToList();
+Assert.Single(typeProperties);
+Assert.Equal("type", typeProperties[0].GetName());

298-332: Clean up commented code or document test intent.

This test contains extensive commented-out assertions which makes it unclear whether this is work-in-progress or intentionally demonstrates unsupported functionality. The comment on Line 298-299 suggests this is intentional, but the commented code should either be removed or properly documented.

 // Note: ResourceShapeFactory only supports getter/setter methods, not direct properties
-// Direct property pattern is not supported by ResourceShapeFactory
+// This test verifies that direct property patterns are NOT supported by ResourceShapeFactory
 [Fact]
-public void CreateResourceShape_WithISetUriProperty_ShouldMapToResourceValueType()
+public void CreateResourceShape_WithISetUriDirectProperty_ShouldNotMapProperty()
 {
     // Arrange
     var resourceType = typeof(TestResourceWithISetUri);

     // Act
     var resourceShape = ResourceShapeFactory.CreateResourceShape(
         BaseUri,
         ResourceShapesPath,
         ResourceShapePath,
         resourceType);

     // Assert
+    // Direct properties are not supported - only getter/setter method patterns
     var properties = resourceShape.GetProperties();
     var uriSetProperty = properties.FirstOrDefault(p => p.GetName() == "uriSet");

     Assert.Null(uriSetProperty);
-    //Assert.Equal("uriSet", uriSetProperty.GetName());
-
-    //var actualValueType = uriSetProperty.GetValueType();
-    //var actualOccurs = uriSetProperty.GetOccurs();
-
-    //Assert.NotNull(actualValueType);
-    //Assert.NotNull(actualOccurs);
-
-    //var expectedValueTypeUri = new Uri(ValueTypeExtension.ToString(OSLC4Net.Core.Model.ValueType.Resource));
-    //var expectedOccursUri = new Uri(OccursExtension.ToString(OSLC4Net.Core.Model.Occurs.ZeroOrMany));
-
-    //Assert.Equal(expectedValueTypeUri, actualValueType);
-    //Assert.Equal(expectedOccursUri, actualOccurs);
-    //Assert.Equal("http://example.com/uriSet", uriSetProperty.GetPropertyDefinition()?.ToString());
 }

392-392: Remove unnecessary 'this' qualifier.

The this qualifier is redundant when there's no naming conflict.

-this._uriCollection = uriCollection;
+_uriCollection = uriCollection;

421-421: Use more readable array initialization.

The current initialization new Uri[0] can be replaced with the more readable Array.Empty<Uri>() for better intent clarity.

-private Uri[] _uriArray = new Uri[0];
+private Uri[] _uriArray = Array.Empty<Uri>();
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e9042f1 and 427b216.

📒 Files selected for processing (2)
  • OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs (1 hunks)
  • OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

⚙️ CodeRabbit Configuration File

**/*.cs: Review the C# code against the Microsoft Framework design guidelines as well as 10 guidelines
from "Building Maintainable Software" by Joost Visser. Point out deviations and improvements.

Files:

  • OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs
🧬 Code Graph Analysis (1)
OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (4)
OSLC4Net_SDK/OSLC4Net.Core/Model/ResourceShapeFactory.cs (5)
  • ResourceShapeFactory (26-513)
  • ResourceShapeFactory (38-59)
  • ResourceShapeFactory (61-63)
  • ValueType (349-359)
  • Occurs (371-381)
OSLC4Net_SDK/OSLC4Net.Domains.RequirementsManagement/Constants.cs (1)
  • RM (27-77)
OSLC4Net_SDK/OSLC4Net.Core/Model/ValueType.cs (1)
  • ValueTypeExtension (59-88)
OSLC4Net_SDK/OSLC4Net.Core/Model/Occurs.cs (1)
  • OccursExtension (38-67)
🔇 Additional comments (5)
OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs (5)

8-13: LGTM! Well-structured test class.

The class structure follows good testing practices with clear constants and descriptive naming conventions.


68-68: Use StringComparison.Ordinal consistently.

Good practice using StringComparison.Ordinal for URI comparisons to avoid culture-specific issues.


187-194: Excellent pattern for URI comparison validation.

This test properly handles the fact that GetValueType() and GetOccurs() return URIs by using the extension methods to get expected URI values for comparison. This pattern should be applied consistently across all similar tests.


337-362: Verify correct OSLC attribute usage pattern.

The test class uses proper OSLC attributes and follows the getter/setter pattern correctly. The implementation properly handles null arrays and uses ISet<Uri> internally while exposing Uri[] externally, which is a common pattern for OSLC properties.


138-159: ResourceShapeFactory: Collection type mappings validated

  • Confirmed that ResourceShapeFactory registers ICollection<Uri>, IEnumerable<Uri>, and ISet<Uri> in its TYPE_TO_VALUE_TYPE dictionary, all mapping to ValueType.Resource.
  • ResourceShapeFactoryTests include coverage for each of these collection types—verifying both the mapped value type and the occurrences setting.

No further action needed.

Assert.NotNull(properties);
Assert.NotEmpty(properties);

var propertyNames = properties.Select(p => p.GetName()).ToList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Missing using directive causes compilation error.

The ToList() method requires using System.Linq; which is missing from the imports.

Add the missing using directive at the top of the file:

+using System.Linq;
🤖 Prompt for AI Agents
In OSLC4Net_SDK/Tests/OSLC4Net.Core.Tests/ResourceShapeFactoryTests.cs around
line 89, the call to ToList() on the LINQ projection requires the System.Linq
namespace which is not imported; add a using System.Linq; directive to the top
of the file alongside the other using statements so the extension methods like
Select and ToList are available and the file compiles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants